Markdown is a way to make fancy documnets. make sure you “knit” often – after every major change – to mitigate errors. Hashtags are how we make section levels of a doc.
This is bold. (that’s double asterisks) or
italics. (that’s single asterisks) Or code.(that’s
back quotes)
To add a hyper link, do [link text](url). For example,
go here
To link to sections of your document, do
[link text](#section-name), no spaces! hyphens. For
example, go here.
To add more verticle space between blocks of text, use this:
Should be more space now.
** To include an image ** first put an image inside the foulder where
your Rmd file is located. Then type
{width="50%"}
RMarkdown is just Markdown with
R code woven in.
You can do R stuff in the same line as text. For example. 6 will show as 6 (it would look like backtick lower-case-r space the code then backtick)
You could also do a full-milti-line CHUNK of R stuff:
# ```{r}
3+3
## [1] 6
#```
eval=TRUE: which actually runs the code; if
FALSE, it shows the code but doesn’t run it.
echo=TRUE : which shows the code; if
FALSE, the code can run without being seen.
warnings=FALSE: which will turn off
warnings.
fig.cap = "figure capption" adds a figure
caption.
fig.width = 7 example of figure width.
fig.height = 4 example of figure height.
# this will be shown but not run
3+3
## [1] 8
To manualy set working directory while building up my Rmarkdown file, just gi to Session > set working directory > Source file location.
library(readr)
energy <- read_csv("../data/IRENA data.csv", skip=1) #ship=1 skips the first row that describes the data
## Rows: 67200 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (5): Country/area, Technology, Data Type, Grid connection, Electricity s...
## dbl (1): Year
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
energy %>% names
## [1] "Country/area" "Technology" "Data Type"
## [4] "Grid connection" "Year" "Electricity statistics"
energy %>% head
## # A tibble: 6 × 6
## `Country/area` Technology `Data Type` `Grid connection` Year
## <chr> <chr> <chr> <chr> <dbl>
## 1 Afghanistan Total renewable Electricity Generation… On-grid 2000
## 2 Afghanistan Total renewable Electricity Generation… On-grid 2001
## 3 Afghanistan Total renewable Electricity Generation… On-grid 2002
## 4 Afghanistan Total renewable Electricity Generation… On-grid 2003
## 5 Afghanistan Total renewable Electricity Generation… On-grid 2004
## 6 Afghanistan Total renewable Electricity Generation… On-grid 2005
## # ℹ 1 more variable: `Electricity statistics` <chr>
energy %>% tail
## # A tibble: 6 × 6
## `Country/area` Technology `Data Type` `Grid connection` Year
## <chr> <chr> <chr> <chr> <dbl>
## 1 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2019
## 2 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2020
## 3 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2021
## 4 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2022
## 5 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2023
## 6 Zimbabwe Nuclear Electricity Generation (GWh) On-grid 2024
## # ℹ 1 more variable: `Electricity statistics` <chr>
energy %>% pull(Technology) %>% unique %>% sort
## [1] "Biogas" "Coal and peat" "Geothermal energy"
## [4] "Natural gas" "Nuclear" "Offshore wind energy"
## [7] "Oil" "Onshore wind energy" "Renewable hydropower"
## [10] "Solar photovoltaic" "Total non-renewable" "Total renewable"
energy %>% pull(`Country/area`) %>% unique()
## [1] "Afghanistan"
## [2] "Albania"
## [3] "Algeria"
## [4] "American Samoa"
## [5] "Andorra"
## [6] "Angola"
## [7] "Anguilla"
## [8] "Antigua and Barbuda"
## [9] "Argentina"
## [10] "Armenia"
## [11] "Aruba"
## [12] "Australia"
## [13] "Austria"
## [14] "Azerbaijan"
## [15] "Bahamas (the)"
## [16] "Bahrain"
## [17] "Bangladesh"
## [18] "Barbados"
## [19] "Belarus"
## [20] "Belgium"
## [21] "Belize"
## [22] "Benin"
## [23] "Bhutan"
## [24] "Bolivia (Plurinational State of)"
## [25] "Bonaire, Sint Eustatius and Saba"
## [26] "Bosnia and Herzegovina"
## [27] "Botswana"
## [28] "Brazil"
## [29] "British Virgin Islands"
## [30] "Brunei Darussalam"
## [31] "Bulgaria"
## [32] "Burkina Faso"
## [33] "Burundi"
## [34] "Cabo Verde"
## [35] "Cambodia"
## [36] "Cameroon"
## [37] "Canada"
## [38] "Cayman Islands"
## [39] "Central African Republic (the)"
## [40] "Chad"
## [41] "Chile"
## [42] "China"
## [43] "China, Hong Kong Special Administrative Region"
## [44] "Chinese Taipei"
## [45] "Colombia"
## [46] "Comoros (the)"
## [47] "Congo (the)"
## [48] "Cook Islands (the)"
## [49] "Costa Rica"
## [50] "Croatia"
## [51] "Cuba"
## [52] "Cura\xe7ao"
## [53] "Cyprus"
## [54] "Czechia"
## [55] "C\xf4te d'Ivoire"
## [56] "Democratic People's Republic of Korea (the)"
## [57] "Democratic Republic of the Congo (the)"
## [58] "Denmark"
## [59] "Djibouti"
## [60] "Dominica"
## [61] "Dominican Republic (the)"
## [62] "Ecuador"
## [63] "Egypt"
## [64] "El Salvador"
## [65] "Equatorial Guinea"
## [66] "Eritrea"
## [67] "Estonia"
## [68] "Eswatini"
## [69] "Ethiopia"
## [70] "Falkland Islands (Malvinas)"
## [71] "Faroe Islands"
## [72] "Fiji"
## [73] "Finland"
## [74] "France"
## [75] "French Guiana"
## [76] "French Polynesia"
## [77] "Gabon"
## [78] "Gambia (the)"
## [79] "Georgia"
## [80] "Germany"
## [81] "Ghana"
## [82] "Greece"
## [83] "Greenland"
## [84] "Grenada"
## [85] "Guadeloupe"
## [86] "Guam"
## [87] "Guatemala"
## [88] "Guinea"
## [89] "Guinea-Bissau"
## [90] "Guyana"
## [91] "Haiti"
## [92] "Honduras"
## [93] "Hungary"
## [94] "Iceland"
## [95] "India"
## [96] "Indonesia"
## [97] "Iran (Islamic Republic of)"
## [98] "Iraq"
## [99] "Ireland"
## [100] "Montenegro"
## [101] "South Sudan"
## [102] "Sint Maarten (Dutch Part)"
## [103] "Israel"
## [104] "Italy"
## [105] "Jamaica"
## [106] "Japan"
## [107] "Jordan"
## [108] "Kazakhstan"
## [109] "Kenya"
## [110] "Kiribati"
## [111] "Kosovo"
## [112] "Kuwait"
## [113] "Kyrgyzstan"
## [114] "Lao People's Democratic Republic (the)"
## [115] "Latvia"
## [116] "Lebanon"
## [117] "Lesotho"
## [118] "Liberia"
## [119] "Libya"
## [120] "Lithuania"
## [121] "Luxembourg"
## [122] "Madagascar"
## [123] "Malawi"
## [124] "Malaysia"
## [125] "Maldives"
## [126] "Mali"
## [127] "Malta"
## [128] "Marshall Islands (the)"
## [129] "Martinique"
## [130] "Mauritania"
## [131] "Mauritius"
## [132] "Mayotte"
## [133] "Mexico"
## [134] "Micronesia (Federated States of)"
## [135] "Mongolia"
## [136] "Montserrat"
## [137] "Morocco"
## [138] "Mozambique"
## [139] "Myanmar"
## [140] "Namibia"
## [141] "Nauru"
## [142] "Nepal"
## [143] "Netherlands (Kingdom of the)"
## [144] "New Caledonia"
## [145] "New Zealand"
## [146] "Nicaragua"
## [147] "Niger (the)"
## [148] "Nigeria"
## [149] "Niue"
## [150] "North Macedonia"
## [151] "Norway"
## [152] "Oman"
## [153] "Pakistan"
## [154] "Palau"
## [155] "Panama"
## [156] "Papua New Guinea"
## [157] "Paraguay"
## [158] "Peru"
## [159] "Philippines (the)"
## [160] "Poland"
## [161] "Portugal"
## [162] "Puerto Rico"
## [163] "Qatar"
## [164] "Republic of Korea (the)"
## [165] "Republic of Moldova (the)"
## [166] "Romania"
## [167] "Russian Federation (the)"
## [168] "Rwanda"
## [169] "R\xe9union"
## [170] "Saint Barth\xe9lemy"
## [171] "Saint Kitts and Nevis"
## [172] "Saint Lucia"
## [173] "Saint Martin (French Part)"
## [174] "Saint Pierre and Miquelon"
## [175] "Saint Vincent and the Grenadines"
## [176] "Samoa"
## [177] "Sao Tome and Principe"
## [178] "Saudi Arabia"
## [179] "Senegal"
## [180] "Serbia"
## [181] "Seychelles"
## [182] "Sierra Leone"
## [183] "Singapore"
## [184] "Slovakia"
## [185] "Slovenia"
## [186] "Solomon Islands"
## [187] "Somalia"
## [188] "South Africa"
## [189] "South Georgia and the South Sandwich Islands"
## [190] "Spain"
## [191] "Sri Lanka"
## [192] "State of Palestine (the)"
## [193] "Sudan (the)"
## [194] "Suriname"
## [195] "Sweden"
## [196] "Switzerland"
## [197] "Syrian Arab Republic (the)"
## [198] "Tajikistan"
## [199] "Thailand"
## [200] "Timor-Leste"
## [201] "Togo"
## [202] "Tokelau"
## [203] "Tonga"
## [204] "Trinidad and Tobago"
## [205] "Tunisia"
## [206] "Turkmenistan"
## [207] "Turks and Caicos Islands"
## [208] "Tuvalu"
## [209] "T\xfcrkiye"
## [210] "Uganda"
## [211] "Ukraine"
## [212] "United Arab Emirates (the)"
## [213] "United Kingdom of Great Britain and Northern Ireland (the)"
## [214] "United Republic of Tanzania (the)"
## [215] "United States Virgin Islands"
## [216] "United States of America (the)"
## [217] "Uruguay"
## [218] "Uzbekistan"
## [219] "Vanuatu"
## [220] "Venezuela (Bolivarian Republic of)"
## [221] "Viet Nam"
## [222] "Yemen"
## [223] "Zambia"
## [224] "Zimbabwe"
#filter data
fenergy <- energy %>%
filter(`Country/area` == 'United States of America (the)')
library(ggplot2)
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
p <-ggplot(fenergy,
aes(x=Year,
y=as.numeric(`Electricity statistics`),
fill=Technology)) + #makes it be numeric
geom_area()
ggplotly(p)
## Warning in FUN(X[[i]], ...): NAs introduced by coercion
## Warning: Removed 26 rows containing non-finite outside the scale range
## (`stat_align()`).